var t = getApp(),
  e = t.requirejs("core");
Page({
  data: {
    icons: t.requirejs("icons"),
    success: false,
    successData: {},
    button_color: t.config.button_color
  },
  onLoad: function (e) {
    
    this.setData({
      options: e
    })
      
  },
  onShow: function () {
    this.get_list()
  },
  to_home:function(){
    e.jump('/yb_mingpian/pages/shop/index',4);
  },
  /**
   *获取订单信息
   * @param order_id 订单id
   * @return array
   */
  get_list: function () {
    var t = this;
    e.get("Miaosha/OrderInfo", { order_id: t.data.options.id}, function (i) {
      0 == i.code ? (
        t.setData({
          list: i.info,
          show: true
        })
      ): e.alert(i.msg)
        
    })
  },

  // 再去逛逛
  viewAround: function () {
    wx.navigateBack({
      delta: 2
    });
  },

  /**
   *调用支付
   * @param out_trade_no 订单号
   * @param openid
   * @return array
   */
  pay: function (t) {
    var i = e.pdata(t).type,
      o = this;
    e.get("Miaosha/Pay", { 
      out_trade_no: o.data.list.out_trade_no,
      openid:getApp().getCache("userinfo").openid
      }, function (t) {
        console.log(t)
      0 == t.code ? (
        wx.requestPayment({
          'timeStamp': t.info.timeStamp,
          'nonceStr': t.info.nonceStr,
          'package': t.info.package,
          'signType': 'MD5',
          'paySign': t.info.paySign,
          'success': function (res) {

            console.log(res)
            if(res.errMsg == "requestPayment:ok"){
              return wx.setNavigationBarTitle({
                title: "支付成功"
              }), void o.setData({
                success: true,
                "list.order_status":1
              });
            }else{
              e.alert('支付失败！')
              wx.redirectTo({
                url: "/yb_mingpian/pages/Miaosha/order/index"
              })
            }
          },
          'fail': function (res) {
            e.alert('您已经取消支付！')
            wx.redirectTo({
              url: "/yb_mingpian/pages/Miaosha/order/index"
            })
          }
        })
      ) : e.alert(t.msg)

    })
      return;
   
  },
  
  phone: function (t) {
    e.phone(t)
  }
})